

//
//  YZQ24HourViewController.m
//  SuperNews
//
//  Created by qiang on 16/1/13.
//  Copyright © 2016年 qiang. All rights reserved.
//

#import "YZQ24HourViewController.h"
#import "YZQ24HourFirstTableViewCell.h"
#import "YZQ24HourSecondTableViewCell.h"
#import "YZQWebViewViewController.h"

@interface YZQ24HourViewController () <UITableViewDelegate, UITableViewDataSource>
@property (nonatomic ,strong) UITableView *myTableView;
@property (nonatomic ,strong) NSMutableArray *AllArray;
@end

@implementation YZQ24HourViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"bobo_top_navigation_back_highlighted"] style:UIBarButtonItemStylePlain target:self action:@selector(leftAction:)];
    
    [self createSubviews];
    [self getData];
    
    // Do any additional setup after loading the view.
}

- (void)createSubviews
{
    [self createTableView];
}

- (void)createTableView {
    
    self.myTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 20, self.view.frame.size.width, self.view.frame.size.height - 113) style:UITableViewStylePlain];
    self.myTableView.delegate = self;
    self.myTableView.dataSource = self;
    [self.view addSubview:self.myTableView];
    [self.myTableView registerClass:[YZQ24HourFirstTableViewCell class] forCellReuseIdentifier:@"firstCell"];
    [self.myTableView registerClass:[YZQ24HourSecondTableViewCell class] forCellReuseIdentifier:@"secondCell"];
    
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.AllArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0) {
        YZQ24HourFirstTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"firstCell" forIndexPath:indexPath];
        NewsPageModel *model = [self.AllArray objectAtIndex:indexPath.row];
        cell.model = model;
        return cell;
    }else {
        
        YZQ24HourSecondTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"secondCell" forIndexPath:indexPath];
        NewsPageModel *model = [self.AllArray objectAtIndex:indexPath.row];
        cell.model = model;
        
        if (indexPath.row == 1) {
            
            cell.numImageV.image = [UIImage imageNamed:@"vote_multi_tag"];
            cell.numLabel.text = @"2";
            cell.numLabel.textAlignment = NSTextAlignmentCenter;
            cell.numLabel.font = [UIFont systemFontOfSize:13];
            cell.numLabel.textColor = [UIColor whiteColor];
        } else if (indexPath.row == 2) {
            
            cell.numImageV.image = [UIImage imageNamed:@"vote_multi_tag"];
            cell.numLabel.text = @"3";
            cell.numLabel.textAlignment = NSTextAlignmentCenter;
            cell.numLabel.font = [UIFont systemFontOfSize:13];
            cell.numLabel.textColor = [UIColor whiteColor];
        } else {
            
            cell.numImageV.image = nil;
            cell.numLabel.text = nil;
        }
        
        return cell;
    }
  
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0) {
        return 260;
    }else {
        return 90;
    }
}


- (void)getData
{
    NSString *urlStr = @"http://c.m.163.com/nc/article/list/T1429173683626/0-20.html";
    [AFNetTool getNetWithURL:urlStr body:nil headFile:nil responseStyle:YZQJSON success:^(NSURLSessionDataTask *task, id responseObject) {
        
        self.AllArray = [NewsPageModel baseModelWithArr:[responseObject objectForKey:@"T1429173683626"]];
        [self.myTableView reloadData];
        
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        
        
    }];
    
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    YZQWebViewViewController *web = [[YZQWebViewViewController alloc]init];
    NewsPageModel *model = [self.AllArray objectAtIndex:indexPath.row];
    web.url = model.url_3w;
    web.docId = model.docid;
    [self.navigationController pushViewController:web animated:YES];
}

- (void)leftAction:(UIBarButtonItem *)sender
{
    [self dismissViewControllerAnimated:YES completion:^{
        
        
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
